﻿using Quartz;
using System.Collections.Specialized;
using Inovout.Gis;
using System.Linq;
using System.ComponentModel;

namespace Inovout.Gis.Job
{
    public class CalculateGeometoryNetAreaJob : IJob
    {
        public readonly string GeometoryIdKeyName = "GeometoryId";
        public readonly string LayerNameKeyName = "LqayerName";


        public void Execute(JobExecutionContext context)
        {
            JobDataMap jobData = new JobDataMap();
            jobData.Put("Server", "172.18.6.217");
            jobData.Put("Instance", "5158");
            jobData.Put("user", "OS_XZ20110409_6AZ2VI");
            jobData.Put("password", "OS_XZ20110409_6AZ2VI");
            jobData.Put("version", "sde.DEFAULT");
            jobData.Put(LayerNameKeyName, "G32_H_PL");
            jobData.Put(GeometoryIdKeyName, "2");

            NameValueCollection datasourceConfig = new NameValueCollection();
            foreach (string key in jobData.Keys)
            {
                datasourceConfig.Add(key, jobData.GetString(key));
            }

            //string pointLayerName = "G33_H_PT";
            //string polygonLayerName = "G31_H_PY";

            IGisInfoRepository gisInfoRepository = RepositoryFactory.GetGisInfoRepository(datasourceConfig);
            string lineLayerName = jobData.GetString(LayerNameKeyName);
            object geometryId = jobData.Get(GeometoryIdKeyName);
            IGeometryObject geometry = gisInfoRepository.GetGeometry(lineLayerName, geometryId) as IGeometryObject;

            geometry.StoreNetArea();
            //    double netArea = geometry.CalculateNetAreaFromSpace();

            //IGeometryLayerElement pointLayer = gisInfoRepository.GetGeometryLayer(pointLayerName) as IGeometryLayerElement;
            //IGeometryLayerElement lineLayer = gisInfoRepository.GetGeometryLayer(lineLayerName) as IGeometryLayerElement;
            //IGeometryLayerElement polygonLayer = gisInfoRepository.GetGeometryLayer(polygonLayerName) as IGeometryLayerElement;

            //GroupLayerElement groupLayer = new GroupLayerElement();
            //groupLayer.AddLayers(pointLayer, lineLayer, polygonLayer);

    

            //IGeometryElement geometry = lineLayer.Geometries.Single(geometryInfo =>
            //    geometryInfo.GeometryId.ToString().Equals(geometryId)) as IGeometryElement;

    

        }
    }
}
